<?php
class user extends CI_Model
{
    public $id;
    public $username;
    public $password;
    public $user_group_code;

    public function get_elements()
    {
        $query = $this->db->query("SELECT * FROM user");
        return $query->result();
    }

    public function get_element_by_id($id)
    {
        $query = $this->db->query("SELECT * FROM user WHERE id = ?",array($id));
        return $query->row();
    }

    public function get_element_by_username_and_password($username,$password)
    {
        $query = $this->db->query("SELECT * FROM user WHERE username = ? AND password = ?",array($username,$password));
        return $query->row();
    }

    public function to_domain_model($item)
    {
        $model = new user();
        $model->id = isset($item->id) ? $item->id : '' ;
        $model->username = isset($item->username) ? $item->username : '' ;
        $model->password = isset($item->password) ? $item->password : '' ;
        $model->user_group_code = isset($item->user_group_code) ? $item->user_group_code : '' ;
        return $model;
    }
}